/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generated_entities;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author aav
 */
@Entity
@Table(name = "RATES")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rates.findAll", query = "SELECT r FROM Rates r"),
    @NamedQuery(name = "Rates.findByBankRegionId", query = "SELECT r FROM Rates r WHERE r.ratesPK.bankRegionId = :bankRegionId"),
    @NamedQuery(name = "Rates.findByCurrencyId", query = "SELECT r FROM Rates r WHERE r.ratesPK.currencyId = :currencyId"),
    @NamedQuery(name = "Rates.findByPurchaseRate", query = "SELECT r FROM Rates r WHERE r.purchaseRate = :purchaseRate"),
    @NamedQuery(name = "Rates.findBySaleRate", query = "SELECT r FROM Rates r WHERE r.saleRate = :saleRate"),
    @NamedQuery(name = "Rates.findByUpdateDate", query = "SELECT r FROM Rates r WHERE r.ratesPK.updateDate = :updateDate")})
public class Rates implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RatesPK ratesPK;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "PURCHASE_RATE", precision = 126)
    private Double purchaseRate;
    @Column(name = "SALE_RATE", precision = 126)
    private Double saleRate;
    @JoinColumn(name = "CURRENCY_ID", referencedColumnName = "CURRENCY_ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Currencies currencies;
    @JoinColumn(name = "BANK_REGION_ID", referencedColumnName = "BANK_REGION_ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private BanksInRegions banksInRegions;

    public Rates() {
    }

    public Rates(RatesPK ratesPK) {
        this.ratesPK = ratesPK;
    }

    public Rates(BigInteger bankRegionId, BigInteger currencyId, Date updateDate) {
        this.ratesPK = new RatesPK(bankRegionId, currencyId, updateDate);
    }

    public RatesPK getRatesPK() {
        return ratesPK;
    }

    public void setRatesPK(RatesPK ratesPK) {
        this.ratesPK = ratesPK;
    }

    public Double getPurchaseRate() {
        return purchaseRate;
    }

    public void setPurchaseRate(Double purchaseRate) {
        this.purchaseRate = purchaseRate;
    }

    public Double getSaleRate() {
        return saleRate;
    }

    public void setSaleRate(Double saleRate) {
        this.saleRate = saleRate;
    }

    public Currencies getCurrencies() {
        return currencies;
    }

    public void setCurrencies(Currencies currencies) {
        this.currencies = currencies;
    }

    public BanksInRegions getBanksInRegions() {
        return banksInRegions;
    }

    public void setBanksInRegions(BanksInRegions banksInRegions) {
        this.banksInRegions = banksInRegions;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ratesPK != null ? ratesPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rates)) {
            return false;
        }
        Rates other = (Rates) object;
        if ((this.ratesPK == null && other.ratesPK != null) || (this.ratesPK != null && !this.ratesPK.equals(other.ratesPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ratesPK.toString() + " Покупка: " + purchaseRate + " Продажа: " + saleRate;   
    }
    
}
